home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / umich / falcon / programm.ing / nt_dsp1.lzh / NT_DSP1.MSA / FFT / FFTR2CN.ASM < prev    next >
Assembly Source File  |  1990-01-17  |  7KB  |  166 lines

  1. ;
  2. ; This program originally available on the Motorola DSP bulletin board.
  3. ; It is provided under a DISCLAMER OF WARRANTY available from
  4. ; Motorola DSP Operation, 6501 Wm. Cannon Drive W., Austin, Tx., 78735.
  5. ; Radix 2, In-Place, Decimation-In-Time FFT (fast).
  6. ; Last Update 18 Aug 88   Version 1.0
  7. ;
  8. fftr2cn  macro   points,data,odata,coef
  9. fftr2cn  ident   1,0
  10. ;
  11. ; Radix 2 Decimation in Time In-Place Fast Fourier Transform Routine
  12. ;
  13. ;    Complex input and output data
  14. ;        Real data in X memory
  15. ;        Imaginary data in Y memory
  16. ;    Normally ordered input data
  17. ;    Normally ordered output data
  18. ;       Coefficient lookup table
  19. ;        -Cosine values in X memory
  20. ;        -Sine values in Y memory
  21. ;
  22. ; Macro Call - fftr2cn   points,data,odata,coef
  23. ;
  24. ;       points     number of points (16-32768, power of 2)
  25. ;       data       start of data buffer
  26. ;       odata      start of output data buffer
  27. ;       coef       start of sine/cosine table
  28. ;
  29. ; Alters Data ALU Registers
  30. ;       x1      x0      y1      y0
  31. ;       a2      a1      a0      a
  32. ;       b2      b1      b0      b
  33. ;
  34. ; Alters Address Registers
  35. ;       r0      n0      m0
  36. ;       r1      n1      m1
  37. ;               n2
  38. ;
  39. ;       r4      n4      m4
  40. ;       r5      n5      m5
  41. ;       r6      n6      m6
  42. ;
  43. ; Alters Program Control Registers
  44. ;       pc      sr
  45. ;
  46. ; Uses 6 locations on System Stack
  47. ;
  48. ; Latest Revision - 18 Aug-88
  49. ;
  50.      move #data,r0            ;initialize input pointer
  51.      move #points/4,n0        ;initialize input and output pointers offset
  52.      move n0,n4               ;
  53.      move n0,n6               ;initialize coefficient offset
  54.      move #points-1,m0        ;initialize address modifiers
  55.      move m0,m1               ;for modulo addressing
  56.      move m0,m4
  57.      move m0,m5
  58. ;
  59. ; Do first and second Radix 2 FFT passes, combined as 4-point butterflies
  60. ;
  61.      move           x:(r0)+n0,x0
  62.      tfr  x0,a      x:(r0)+n0,y1   
  63.  
  64.      do   n0,_twopass
  65.      tfr  y1,b      x:(r0)+n0,y0
  66.      add  y0,a      x:(r0),x1                     ;ar+cr
  67.      add  x1,b      r0,r4                         ;br+dr
  68.      add  a,b       (r0)+n0                       ;ar'=(ar+cr)+(br+dr)
  69.      subl b,a       b,x:(r0)+n0                   ;br'=(ar+cr)-(br+dr)
  70.      tfr  x0,a      a,x0           y:(r0),b
  71.      sub  y0,a                     y:(r4)+n4,y0   ;ar-cr
  72.      sub  y0,b      x0,x:(r0)                     ;bi-di
  73.      add  a,b                      y:(r0)+n0,x0   ;cr'=(ar-cr)+(bi-di)
  74.      subl b,a       b,x:(r0)                      ;dr'=(ar-cr)-(bi-di)
  75.      tfr  x0,a      a,x0           y:(r4),b
  76.      add  y0,a                     y:(r0)+n0,y0   ;bi+di
  77.      add  y0,b      x0,x:(r0)+n0                  ;ai+ci
  78.      add  b,a                      y:(r0)+,x0     ;ai'=(ai+ci)+(bi+di)
  79.      subl a,b                      a,y:(r4)+n4    ;bi'=(ai+ci)-(bi+di)
  80.      tfr  x0,a                     b,y:(r4)+n4
  81.      sub  y0,a      x1,b                          ;ai-ci
  82.      sub  y1,b      x:(r0)+n0,x0                  ;dr-br
  83.      add  a,b       x:(r0)+n0,y1                  ;ci'=(ai-ci)+(dr-br)
  84.      subl b,a                      b,y:(r4)+n4    ;di'=(ai-ci)-(dr-br)
  85.      tfr  x0,a                     a,y:(r4)+
  86. _twopass
  87. ;
  88. ; Perform all next FFT passes except last pass with triple nested DO loop
  89. ;    
  90.      move #points/8,n1        ;initialize butterflies per group
  91.      move #4,n2               ;initialize groups per pass
  92.      move #-1,m2              ;linear addressing for r2
  93.      move #0,m6               ;initialize C address modifier for
  94.                               ;reverse carry (bit-reversed) addressing
  95.  
  96.      do   #@cvi(@log(points)/@log(2)-2.5),_end_pass    ;example: 7 passes for 1024 pt. FFT
  97.      move #data,r0                                     ;initialize A input pointer
  98.      move r0,r1
  99.      move n1,r2
  100.      move r0,r4                                        ;initialize A output pointer
  101.      move (r1)+n1                                      ;initialize B input pointer
  102.      move r1,r5                                        ;initialize B output pointer
  103.      move #coef,r6                                     ;initialize C input pointer
  104.      lua  (r2)+,n0                                     ;initialize pointer offsets
  105.      move n0,n4
  106.      move n0,n5
  107.      move (r2)-                                        ;butterfly loop count
  108.      move           x:(r1),x1      y:(r6),y0           ;lookup -sine and -cosine values
  109.      move           x:(r6)+n6,x0   y:(r0),b            ;update C pointer, preload data
  110.      mac  x1,y0,b                  y:(r1)+,y1
  111.      macr -x0,y1,b                 y:(r0),a
  112.  
  113.      do   n2,_end_grp
  114.      do   r2,_end_bfy
  115.      subl b,a       x:(r0),b       b,y:(r4)            ;Radix 2 DIT butterfly kernel
  116.      mac  -x1,x0,b  x:(r0)+,a      a,y:(r5)
  117.      macr -y1,y0,b  x:(r1),x1
  118.      subl b,a       b,x:(r4)+      y:(r0),b
  119.      mac  x1,y0,b                  y:(r1)+,y1
  120.      macr -x0,y1,b  a,x:(r5)+      y:(r0),a
  121. _end_bfy
  122.      move (r1)+n1
  123.      subl b,a       x:(r0),b       b,y:(r4)
  124.      mac  -x1,x0,b  x:(r0)+n0,a    a,y:(r5)
  125.      macr -y1,y0,b  x:(r1),x1      y:(r6),y0
  126.      subl b,a       b,x:(r4)+n4    y:(r0),b
  127.      mac  x1,y0,b   x:(r6)+n6,x0   y:(r1)+,y1
  128.      macr -x0,y1,b  a,x:(r5)+n5    y:(r0),a
  129. _end_grp
  130.      move n1,b1
  131.      lsr  b    n2,a1     ;divide butterflies per group by two
  132.      lsl  a    b1,n1     ;multiply groups per pass by two
  133.      move a1,n2
  134. _end_pass
  135. ;
  136. ; Do last FFT pass
  137. ;
  138.      move #2,n0          ;initialize pointer offsets
  139.      move n0,n1
  140.      move #points/4,n4   ;output pointer A offset
  141.      move n4,n5          ;output pointer B offset
  142.      move #data,r0       ;initialize A input pointer
  143.      move #odata,r4      ;initialize A output pointer
  144.      move r4,r2          ;save A output pointer
  145.      lua  (r0)+,r1       ;initialize B input pointer
  146.      lua  (r2)+n2,r5     ;initialize B output pointer
  147.      move #0,m4          ;bit-reversed addressing for output ptr. A
  148.      move m4,m5          ;bit-reversed addressing for output ptr. B
  149.      move #coef,r6       ;initialize C input pointer
  150.      move (r5)-n5        ;predecrement output pointer
  151.      move           x:(r1),x1      y:(r6),y0
  152.      move           x:(r5),a       y:(r0),b
  153.  
  154.      do   n2,_lastpass
  155.      mac  x1,y0,b   x:(r6)+n6,x0   y:(r1)+n1,y1   ;Radix 2 DIT butterfly kernel
  156.      macr -x0,y1,b  a,x:(r5)+n5    y:(r0),a       ;with one butterfly per group
  157.      subl b,a       x:(r0),b       b,y:(r4)
  158.      mac  -x1,x0,b  x:(r0)+n0,a    a,y:(r5)
  159.      macr -y1,y0,b  x:(r1),x1      y:(r6),y0
  160.      subl b,a       b,x:(r4)+n4    y:(r0),b
  161. _lastpass
  162.      move           a,x:(r5)+n5
  163.      endm
  164. ^Z